package com.cw.reduce.filter;

import java.util.Vector;

public class ContainFilter implements IFilter {

	private int which;

	public ContainFilter(int which) {
		this.which = which;
	}

	@Override
	public Vector startFilter(Vector condition, Vector<Integer> target) {

		Vector<Integer> result = new Vector<Integer>();
		switch (which) {
		case 0:
			for (Integer e : target) {
				String e2Str = e.toString();
				if (e < 100 && condition.contains(0)) {
					result.addElement(e);
					continue;
				}
				for (int i = 0; i < e2Str.length(); i++) {
					if (condition.contains(Integer.parseInt(e2Str.substring(i,
							i + 1)))) {
						result.addElement(e);
						break;
					}
				}
			}
			break;

		case 1:
			for (Integer e : target) {
				String e2Str = e.toString();
				if (e < 100 && condition.contains(0)) {
					// result.addElement(e);
					continue;
				}
				int count = 0;
				for (int i = 0; i < e2Str.length(); i++) {
					if (!condition.contains(Integer.parseInt(e2Str.substring(i,
							i + 1)))) {
						// result.addElement(e);
						if (count == e2Str.length() - 1
								&& i == e2Str.length() - 1) {
							result.addElement(e);
						}
						count++;
						continue;
					}
				}
			}
			break;

		default:
			break;

		}
		return result;
	}

}
